<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/WEB-INF/struts-tags.tld"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>欢迎访问产品运营互动中心！</title>
<link rel="stylesheet" href="<s:url value="/css/style_new.css"/>">
<script type="text/javascript" src="<s:url value="/script/sysOper.js"/>"></script>
<script type="text/javascript" src="<s:url value="/script/jquery.js"/>"></script>
<script type="text/javascript">
	function go(){
		var selIndex=$("select[name=wholeRoles]")[0].selectedIndex; 
		//var item = $("select[@name=wholeRoles] option[@selected]").text(); 
		if (selIndex==-1){
			alert("请选择需要赋予用户的角色！");
		}else{
		var val=$("select[name=wholeRoles]").val(); 
		var txt = ($("select[name=wholeRoles]")[0])[selIndex].text; 
		var len=$("select[name=selectedRole]")[0].length;
		var option = "<option value='" + val + "'>" + txt + "</option>";
		if (len==0){
			$("select[name=selectedRole]").append(option);
			$("input[name=selectedRoles]")[0].value=val;
		}else{
			var isSel=false;
			$("select[name=selectedRole]").find("option").each(function(i){
	              var key = ($("select[name=selectedRole]")[0])[i].value;
	              if (key==val){
					isSel=true;
	              }
	         });
	         if (isSel){
				alert("此角色已选择！");
	         }else{
		        $("select[name=selectedRole]").append(option);
				$("input[name=selectedRoles]")[0].value=$("input[name=selectedRoles]")[0].value+","+val;
	         }
		}
			
		}
	}
	
	function unselect(){
		var selIndex=$("select[name=selectedRole]")[0].selectedIndex; 
		var len=$("select[name=selectedRole]")[0].length;
		$("select[name=selectedRole]").find("option").each(function(i){
			if (i>=selIndex && i<len-1){
				($("select[name=selectedRole]")[0])[i].value=($("select[name=selectedRole]")[0])[i+1].value;
				($("select[name=selectedRole]")[0])[i].text=($("select[name=selectedRole]")[0])[i+1].text;
			}
        });
		$("select[name=selectedRole]")[0].length=len-1;
		setSelectedRole();
	}
	
	function setSelectedRole(){
		var currVal="";
		$("select[name=selectedRole]").find("option").each(function(i){
			if (i==0) {
				currVal=($("select[name=selectedRole]")[0])[i].value;
			}else{
				currVal+=","+($("select[name=selectedRole]")[0])[i].value;
			}
         });
         $("input[name=selectedRoles]")[0].value=currVal;
	}
</script>
<script type="text/javascript" src="<s:url value="/script/selfResize.js"/>"></script>
<script>
function initLoad(){
	f_iframeResize();
}
window.onload = initLoad;
</script>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0">
<table width="980" border="0" cellspacing="0" cellpadding="0"
	align="center">
			<tr>
				<td>
					<table width="100%" border="0" cellpadding="0" cellspacing="0"
						background="<s:url value="/images/new/gxzl_index_2.gif"/>">
						<tr>
							<td width="20" height="32">
								&nbsp;
							</td>
							<td width="20">
								<img src="<s:url value="/images/new/dq_dot.gif"/>" width="15"
									height="12" />
							</td>
							<td>
								<font color="#FFFFFF">当前位置：系统管理&gt;&gt;权限管理&gt;&gt;资源管理</font>
							</td>
							<td></td>
						</tr>
					</table>
				</td>
			</tr>
	<tr>
		<td background="<s:url value="/images/home_4a.gif"/>">
		<table width="100%" border="0" cellspacing="0" cellpadding="0"
			align="center" bgcolor="#FFFFFF">
			<tr>
				<td width="20%" valign="top">
		 		<%@ include file="/commons/include/secu_left.inc"%>  
				</td>
				<td valign="top" align="center">
				<br>
				<s:form name="roleRelaUserForm" action="/security/saveRoleRelaUser.action"
					method="post">
					<table width="660" border="0" cellspacing="0" cellpadding="0"
						background="<s:url value="/images/catalog_manage_8b.gif"/>">
						<tr>
							<td><img src="<s:url value="/images/catalog_manage_8.gif"/>" width=660
								height=11 alt=""></td>
						</tr>
						<tr>
							<td>
							<TABLE width="80%" cellSpacing=1 cellPadding=0 align="center">
								<TR height=30>
									<TD align=left width="10%">
				                      <input type="button" name="save" onclick="submit();"  value="保　存">
				                      <input type="button" name="save" onclick="location.href='listUser.action';"  value="返　回">
									</TD>
								</TR>
							</table>
							<input type="hidden" name="conds.userID" value="${roleRelaUser.user.id}"/>
							<input type="hidden" name="selectedRoles" value="${selectedRoles}"/>
							<input type="hidden" name="userID" value="${roleRelaUser.user.id}"/>
							<input type="hidden" name="roleRelaUser.user.id" value="${roleRelaUser.user.id}"/>
							<div name="dSelected" style="height:0px"></div>
							<table width="80%" border="0" cellspacing="0" cellpadding="7"
								align="center" class=tablecolor2>
								<tr>
									<td colspan="3" align="left">
									操作用户：<font color="red"><b>${roleRelaUser.user.userID}</b></font>
									</td>
								</tr>
								<tr>
									<td align="center" width="45%">
									系统所有角色
									</td>
									<td align="center">
									</td>
									<td align="center" width="45%">
									赋予角色
									</td>
								</tr>
								<tr>
									<td align="center">
									<s:select name="wholeRoles" list="roles"
										listKey="id" listValue="name" theme="css_xhtml" 
										size="20" cssClass="SELECTSTYLE" ondblclick="go()"/>
									</td>
									<td align="center">
										<input type="button" name="btnGo" value="->" onclick="go()"/>
									</td>
									<td align="center">
									<s:select name="selectedRole"
										list="roleRelaUsers" listKey="role.id" listValue="role.name"
										theme="css_xhtml" size="20"  cssClass="SELECTSTYLE" ondblclick="unselect()"/>
									</td>
								</tr>
							</table>
							</td>
						</tr>
						<tr>
							<td>
								<img src="<s:url value="/images/catalog_manage_8a.gif"/>" width="660"
								height="9">
							</td>
						</tr>
					</table>
				</s:form> 
				</td>
			</tr>
		</table>
</body>
</html>

